﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml.Serialization;

namespace Server
{
    /// <summary>
    /// server 的摘要说明
    /// </summary>
    public class server : IHttpHandler
    {
        public class WeatherItemClass
        {
            public String description { get; set; }
            public double highTemp { get; set; }
            public double lowTemp { get; set; }
            public override string ToString()
            {
                return description + "," + lowTemp.ToString() + "," + highTemp.ToString();
            }
        }
        public class WeatherClass
        {
            public String city { get; set; }
            public String date { get; set; }
            public WeatherItemClass weather { get; set; }
            public override string ToString()
            { return city + "," + date + "," + weather.ToString(); }
        }

        String serialize(WeatherClass w)
        {
            XmlSerializer xml = new XmlSerializer(typeof(WeatherClass));
            MemoryStream ms = new MemoryStream();
            xml.Serialize(ms, w);
            String s = Encoding.UTF8.GetString(ms.ToArray());
            return s;
        }

        public void ProcessRequest(HttpContext context)
        {
            context.Request.ContentType = "text/plain";
            WeatherClass w = new WeatherClass
            {
                city = "武汉",
                date = "2023-03-03",
                weather = new WeatherItemClass
                {
                    description = "多云<晴天>",
                    lowTemp = 6,
                    highTemp = 16,
                }
            };
            String s = serialize(w);
            context.Response.Write(s);
        }
        public bool IsReusable
        {
            get { return false; }
        }

    }
}